/* This is a map editor designed by my entire team (Cookie, Sebass, and myself)
 *However I programmed it in its entirety
 *Date: 4/26/08
 *Programmer: William McAllister
 *Version: 0.2
 */

package components;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

// All of these files are just imports that are required for the GUI portion of
// the editor

public class MapEditor extends JFrame implements ActionListener, MouseListener {
    /**
     * long serialVersionUID
     */
    private static final long serialVersionUID = 1L;
    JTextArea JTA;
    JScrollPane scrollPane;
    JTextArea output;

    JMenuItem saveO;
    JMenuItem closeO;
    JMenuItem newO;
    JTextField textField;
    JTextArea textArea;

    int[][] overlay;
    int[][] tileSet;

    String overlayLoc;
    String tileSetLoc;
    JFrame frame;
    JFrame saveF;
    JDesktopPane desktop;

    public JMenuBar menu() {
	JMenuBar menuBar;
	JMenu menu;

	menuBar = new JMenuBar();
	menu = new JMenu("Options"); // This creates a new menu tab called
					// Options
	menu.setMnemonic(KeyEvent.VK_O); // Makes it so that hitting alt+O
					    // will bring up the Options menu
	menuBar.add(menu);

	newO = new JMenuItem("New");
	saveO = new JMenuItem("Save"); // Creates an option that is called Save
	closeO = new JMenuItem("Close");
	newO.addMouseListener(this);
	saveO.addMouseListener(this);
	closeO.addMouseListener(this);
	menu.add(newO);
	menu.add(saveO); // Displays Save int the Options tab
	menu.add(closeO);

	return menuBar;
    }

    public Container contentPane() {
	JPanel contentPane = new JPanel(new BorderLayout());
	contentPane.setOpaque(true);

	return contentPane;
    }

    public static void displayGUI() {
	JFrame frame = new JFrame("Map Editor"); // This creates the blue
						    // frame around the window
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // This makes it
								// so that
								// clicking on
								// the red X
								// closes the
								// window
	MapEditor map = new MapEditor();
	frame.setJMenuBar(map.menu());
	frame.setContentPane(map.contentPane());

	frame.setSize(600, 600);
	frame.setVisible(true);
    }

    public static void main(String[] args) {
	javax.swing.SwingUtilities.invokeLater(new Runnable() {
	    public void run() {
		displayGUI();
	    }
	});
    }

    public void mouseExited(MouseEvent e) {

    }

    public void mouseEntered(MouseEvent e) {

    }

    public void mouseClicked(MouseEvent e) {
    }

    public void mousePressed(MouseEvent e) {
    }

    public void mouseReleased(MouseEvent e) {
	if (e.getSource().equals(closeO)) {
	    System.exit(0);
	}
	if (e.getSource().equals(saveO)) {

	}

	if (e.getSource().equals(newO)) {
	    saveF = new JFrame("Save Location");
	    saveF.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
	    MapEditor saveM = new MapEditor();
	    saveF.setContentPane(saveM.contentPane());
	    saveF.setSize(300, 150);
	    saveF.setVisible(true);

	}
    }

    public void newDisplay() {
	new GridBagLayout();

	textField = new JTextField(20);
	textField.addActionListener(this);
	GridBagConstraints c = new GridBagConstraints();
	c.gridwidth = GridBagConstraints.REMAINDER;

	textArea = new JTextArea(5, 20);
	textArea.setEditable(false);
	JScrollPane scrollPane = new JScrollPane(textArea);

	c.fill = GridBagConstraints.HORIZONTAL;
	add(textField, c);

	c.fill = GridBagConstraints.BOTH;
	c.weightx = 1.0;
	c.weighty = 1.0;
	add(scrollPane, c);
    }

    public void action(ActionEvent evt) {

    }

    public void actionPerformed(ActionEvent arg0) {
	// TODO Auto-generated method stub

    }

}